package com.wyh.controller.groupOne.customer;

import com.wyh.common.enums.ResultCodeEnum;
import com.wyh.common.exception.CustomException;
import com.wyh.common.result.Result;
import com.wyh.domain.po.groupOne.customer.MasterDataContacts;
import com.wyh.service.groupOne.customer.MasterDataCCustomerService;
import com.wyh.service.groupOne.customer.MasterDataContactsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "联系人管理API")
@RestController
@RequestMapping("contacts")
public class ContactsController {

    @Autowired
    private MasterDataContactsService masterDataContactsService;

    @Autowired
    private MasterDataCCustomerService masterDataCCustomerService;

    /**
     * 查询跟该客户相关的所有联系人
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "查询跟该客户相关的所有联系人")
    @GetMapping("selectAll/{id}")
    public Result selectAll(@PathVariable Integer id) {
        if (id == null) {
            throw new CustomException(ResultCodeEnum.ORGANIZATION_FIND_ERROR);
        }
        List<MasterDataContacts> masterDataContactsList = masterDataContactsService.selectAll(id);
        return Result.success(masterDataContactsList);
    }

//    /**
//     * 添加联系人
//     * @param contacts
//     * @return
//     */
//    @PostMapping("add")
//    public Result add(@RequestBody MasterDataContacts contacts){
//        masterDataContactsService.insert(contacts);
//        return Result.success();
//    }

    /**
     * 删除联系人
     * @param id
     * @return
     */
    @ApiOperation(value = "删除联系人")
    @GetMapping("delete/{id}")
    public Result delete(@PathVariable Integer id) {
        if (id != null) {
            masterDataContactsService.delete(id);
            return Result.success();
        }
        return Result.error(ResultCodeEnum.ORGANIZATION_DELETE_ERROR);
    }

    /**
     * 查询所有楼盘
     * @return
     */
    @ApiOperation(value = "查询所有楼盘")
    @GetMapping("/selectAllName")
    public Result selectAllName(){
        return Result.success(masterDataCCustomerService.selectAllName());
    }


}
